package com.winning.sx.microframework.service.sysmanage;

import com.winning.dapi.data.entity.DataTable;
import com.winning.sx.microframework.dao.sysmanage.RoleManageDao;
import com.winning.sx.microframework.model.exception.CustomException;
import com.winning.sx.microframework.model.manage.RoleManageModel;
import com.winning.sx.microframework.common.util.BaseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

/**
 * Created by xiaoY on 2017/2/13.
 */
@Service
public class RoleManageService {
    @Autowired
    private RoleManageDao roleManageDao;

    public DataTable queryRoles() throws CustomException {
        return roleManageDao.queryRoles();
    }

    public int editRole(RoleManageModel roleModel) throws CustomException {
        int result = 0;
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        roleModel.setcInputTime(sdf.format(date));
        Map<String, Object> roleMap = BaseUtil.beanToMap(roleModel);
        result = roleManageDao.updateRole(roleMap);
        if (result == 0) {
            result = roleManageDao.insertRole(roleMap);
        }
        return result;
    }

    public int delRole(RoleManageModel roleModel) throws CustomException {
        int result = 0;
        Map<String, Object> roleMap = BaseUtil.beanToMap(roleModel);
        result = roleManageDao.deleteRole(roleMap);
        return result;
    }

    public DataTable queryRSasso(Map map) throws CustomException {
        return roleManageDao.queryRSasso(map);
    }

    public int saveAsso(Map map) throws CustomException {
        return roleManageDao.saveAsso(map);
    }

}
